
import json
import socket
import logging
from flask import Flask, request
server = Flask(__name__)

# log日志
logging.basicConfig(level = logging.DEBUG,format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
@server.route("/push",methods=['post'])
def main():

    # 1 创建tcp套接字
    tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    # 2 创建连接
    tcp_socket.connect(('49.234.30.189', 8631))

    # 3 发送数据
    data = json.loads(request.data)
    logging.debug("data:%s"%data)
    tcp_input = request.data
    logging.debug("tcp_input:%s"%tcp_input)
    tcp_socket.send(tcp_input)  # utf-8 中文会乱码

    # 4.关闭套接字
    tcp_socket.close()
    return ""
if __name__ == '__main__':
    # test()
    server.run(host="0.0.0.0",port=8632, debug=True)
